package com.weakteam.orderonline.adminconsole.gwt.client.widget;


import com.google.gwt.user.client.ui.HTML;
import com.weakteam.orderonline.adminconsole.gwt.client.domain.Goods;
import com.weakteam.orderonline.adminconsole.gwt.client.util.uploader.file.FileUtil;


/**
 * Created by Max on 02.04.2014.
 */
public class MenuGoodsBox extends HTML {

    private Goods goods;

    private Boolean selected;

    public MenuGoodsBox(Goods goods) {
        this.goods = goods;
        this.selected = false;
        this.setData(goods);
        this.setEnabled(goods.getEnabled());
        this.setStyleName("category-item");
    }

    public Boolean isSelected() {
        return selected;
    }
    public Goods getGoods(){
        return this.goods;
    }
    public int getGoodsId() {
        return this.goods.getId();
    }
    public void setGoodsOrder (int index) {
        this.goods.setOrder(index);
    }


    public void setData(Goods data) {
        String html = "<div>"+data.getName()+"</div>" +
                      "<img onmousedown=\"return false\" class=\"category-item\"" +
                      "src=\"" + FileUtil.getImageURL(data.getImage())+"\">";
        this.setHTML(html);
    }

    public void setSelected(Boolean selected) {
        this.selected = selected;
        if (selected) {
            this.addStyleName("content-item-selected");
        } else {
            this.removeStyleName("content-item-selected");
        }
    }

    public void setEnabled(Boolean enabled) {
        if (enabled) {
            this.removeStyleName("content-item-disabled");
        } else {
            this.addStyleName("content-item-disabled");
        }
    }

}